﻿using GEPL.InterfaceLibrary;
using GEPL.StandardModulesLibrary.ViewModels.Common;
using GEPL.StandardModulesLibrary.Views.Common;
using System;
using System.Runtime.Serialization;

namespace GEPL.StandardModulesLibrary.Elements.Common
{
    [Serializable]
    public class RawScriptElement : IElement
    {
        private readonly RawScriptViewModel viewModel;

        public RawScriptElement()
        {
            viewModel = new RawScriptViewModel();
        }

        /// <summary>
        /// Deserialization constructor
        /// </summary>
        public RawScriptElement(SerializationInfo info, StreamingContext context)
            : this()
        {
            viewModel = new RawScriptViewModel()
            {
                Script = info.GetString(nameof(viewModel.Script))
            };
        }

        public ElementType ElementType
        {
            get { return ElementType.NormalStatement; }
        }

        public ProjectType ProjectType
        {
            get { return ProjectType.Any; }
        }

        public string ElementName
        {
            get { return Properties.Resources.Names_RawScript; }
        }

        public object Data
        {
            get { return viewModel; }
        }

        public Type UserControlType
        {
            get { return typeof(RawScriptView); }
        }

        public string GetScript()
        {
            return viewModel.Script;
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue(nameof(viewModel.Script), viewModel.Script, typeof(String));
        }
    }
}